angular.module('mamApp').controller('transcodingProgramsDetailController', ['$scope', 'TranscodingManager', '$state', '$sce', 'ImsDialog','ImageManager',
    function ($scope, TranscodingManager, $state, $sce, ImsDialog,ImageManager) {
        $scope.$sce = $sce;

        $scope.search={mode:$state.params.mode};

        $scope.albumId = $state.params.albumId;
        $scope.albumName = $state.params.albumName;
        $scope.programId = $state.params.programId;




        TranscodingManager.transcodingProgramsAudioList($scope.programId).then(function (result) {
            $scope.audioList = result.data.pageList;
            $scope.program = result.data.programVO;

            $scope.images=ImageManager.coverImageList($scope.program.programCover);
        })


        $scope.audioReconvert = function (audio) {

            ImsDialog.open({title: "转码确认", message: "确定为当前的音频重新转码吗？"}).then(function (a) {
                if (a == "ok") {

                    var params = {audioId: audio.id, format: audio.format, bitRates: audio.bitRate};
                    TranscodingManager.audioReconvert(params).then(function (result) {
                        if (result.data.c == "s") {
                            $state.reload();
                        }
                    })
                }
            })


        }

        $scope.modeChange=function (mode) {
            $scope.search.mode=mode;
            $state.go($state.current.name,$scope.search)
        }

        $scope.imageReconvert = function (image) {

            ImsDialog.open({title: "转码确认", message: "确定为当前的图片重新转码吗？"}).then(function (a) {
                if (a == "ok") {

                    var params = {webUrl: $scope.program.programCover, pixels:[image.imageWidth+"_"+image.imageHeight]};
                    TranscodingManager.imageReconvert(params).then(function (result) {
                        if (result.data.c == "s") {
                            $state.reload();
                        }
                    })
                }
            })


        }

    }])

